<?php
include_once("../function.php");

//print_r($_POST);die;//Array ( [usname] => qqqqqqqqqq [pwd] => 123456 [repwd] => 123456 [phone] => 15861880507 [email] => 123@qq.com [yzm] => omwc [check2] => 接受 [sub] => 注册 )
//判断是否通过表单提交
if(!isset($_POST["sub"]))
{
	msg("请通过表单提交","./regist.php");exit;
}
extract($_POST);//$usname $pwd $repwd $phone $email 
//数据处理
$usname=trim($usname);
$pwd=trim($pwd);
//$repwd=trim($repwd);
$phone=trim($phone);
//$email=trim($email);
if($email!="")
{
	$email=trim($email);
}
else
{
	$email="";
}
//判断用户名是否已注册
$sql="select * from ts_user where usernme='$usname'";
$res=mysqli_query($link,$sql);
if(is_object($res))
{
	if(mysqli_num_rows($res)==1)
	{
		msg("该用户已存在","./regist.php");exit;
	}
}

//注册信息入库
$pwd=md5($pwd);
$sql="insert into ts_user(username,password,mobile,email,admin,ifshow) values('$usname','$pwd','$phone','$email','0','1')";
$res=mysqli_query($link,$sql);
//echo $sql;die;
if($res)
{
	if(mysqli_affected_rows($link)==1)
	{
		msg("注册成功","./login.php");exit;
	}
	else
	{
		msg("注册失败","./regist.php");exit;
	}
}
?>